import 'dart:convert';
import 'dart:io';

import 'package:eshi/app/shi/data/Config.dart';
import 'package:eshi/app/shi/data/HistoryMarks.dart';
import 'package:eshi/app/shi/data/parse/FileParser.dart';

//标记
class HistoryMark{
  String get host => Config.netHost;
  final path = "";

  String doc;
  Function(String type, String name) addMark;
  
  HistoryMark(this.doc, this.addMark){
      localeMarks();
      netMarks();
  }

  //本地标记
  localeMarks() {
    HistoryMarks.values
      .map((t) => t.name )
      .forEach((type){
          FileParser.readDirFiles(directoryPath: "assets/$type/").then((names){
              names.keys
                .where((vv) => doc.contains(vv) )  
                .forEach((name) => addMark(type,name));
          });
      });
  }
  //网络标记 
  netMarks(){
    if(host.isNotEmpty) {
      HttpClient().postUrl(Uri.http(host ,path,{"doc":doc})).then((res){
        var json = jsonDecode(res.toString());
        Map<String,List<String>> data = json.data;
        data.forEach((k,v){
           for (var name in v) {
             addMark(k,name);
           }   
        });
    });
    }
  }
}